#define _CRT_SECURE_NO_WARNINGS 1


class Foo {
private:
    sem_t _first_sem;
    sem_t _second_sem;
public:
    Foo() {
        sem_init(&_first_sem, 0, 0);
        sem_init(&_second_sem, 0, 0);
    }

    void first(function<void()> printFirst) {
        // printFirst() outputs "first". Do not change or remove this line.
        printFirst();
        sem_post(&_first_sem);
    }

    void second(function<void()> printSecond) {
        sem_wait(&_first_sem);
        // printSecond() outputs "second". Do not change or remove this line.
        printSecond();
        sem_post(&_second_sem);
    }

    void third(function<void()> printThird) {
        sem_wait(&_second_sem);
        // printThird() outputs "third". Do not change or remove this line.
        printThird();
    }
};